\documentclass[a4paper]{article}
\usepackage{xltxtra}
\usepackage{graphicx}
\usepackage{fontspec}
\usepackage{cite}
\usepackage{geometry}
\usepackage{amsmath}

\geometry{left=20mm,right=20mm,top=20mm,bottom=20mm}
\begin{document}  

\title{Design}  
\author{Jiang Zhou 3220101339}   
\date{2024.12}  
\maketitle  
\section{Spline.hpp}
This file Spline.hpp defines a hierarchy of classes for spline interpolation.   Below is a structured explanation of the program structure, design, class interfaces, relationships, and the mathematical theories used.

\subsection{Program Structure and Design}
\subsubsection*{Abstract Base Class Spline}
Defines the interface for all spline types with a pure virtual function getSplineValue in order to get the value of $x$ on the spline.
\subsubsection*{Class LinearPPForm}
Implements linear piecewise polynomial interpolation using the piecewise polynomial form.
\subsubsection*{Class PPForm}
Implements cubic spline interpolation with different boundary conditions (natural, periodic, complete).
\subsubsection*{Class LinearBSpline}
Implements linear B-spline interpolation.
\subsubsection*{Class BSpline}
Implements higher-degree B-spline interpolation with various boundary conditions.


\subsection{Mathematical Theories and Equations}
\subsubsection*{Linear Interpolation}
\[ P_1(x) = y_i + \frac{y_{i+1} - y_i}{x_{i+1} - x_i}(x - x_i) \]

\subsubsection*{Cubic Spline Interpolation}
For a cubic spline, the polynomial between two knots $x_i$ and $x_{i+1}$ is given by:
\[ S_i(x) = a_i + b_i(x - x_i) + c_i{x - x_i}^2 + d_i{x - x_i}^3 \]
Where:
\[ a_i = y_i \]
\[ b_i = y'_i \]
\[ c_i = \frac{3}{h_i}(y_{i+1} - y_i) - \frac{2h_i}{6}(y'_i + y'_{i+1}) \]
\[ d_i = \frac{h_i}{6}(y'_i + y'_{i+1}) - \frac{2}{h_i}(y_{i+1} - y_i) \]

Here, $h_i = x_{i+1} - x_i$, $y_i$ and $y_{i+1}$ are the function values at the knots, and $y'_i$ and $y'_{i+1}$ are the first derivatives at the knots.

\subsubsection*{B-Spline Basis Functions}
\[ B_{i,k}(t) = \begin{cases} 
\frac{t - x_i}{x_{i+k} - x_i}B_{i,k-1}(t) + \frac{x_{i+k+1} - t}{x_{i+k+1} - x_{i+1}}B_{i+1,k-1}(t) & \text{if } x_i \leq t < x_{i+k+1} \\
0 & \text{otherwise}
\end{cases} \]
\subsubsection*{Natural Boundary Conditions}
\[ S''(x_0) = 0, \quad S''(x_n) = 0 \]
\subsubsection*{Periodic Boundary Conditions}
\[ S(x_0) = S(x_n), \quad S'(x_0) = S'(x_n), \quad S''(x_0) = S''(x_n) \]
\subsubsection*{Complete Boundary Conditions}
\[ S'(x_0) = f_a, \quad S'(x_n) = f_b \]

\section{Curvefitting.hpp}
The design is to provide a flexible and reusable set of functions for curve fitting using B-splines.   The functions are designed to handle different scenarios, such as cumulative chordal length parameterization and equidistant node parameterization, in both 2D and 3D spaces.
\subsection{Cumulative Chordal Length Parameterization}
The cumulative chordal length parameterization is calculated using the following equation:
\[ t_i = t_{i-1} + \frac{d_{i}}{L} \]
Where:
\[ d_{i} = \sqrt{{x_i - x_{i-1}}^2 + {y_i - y_{i-1}}^2 + {z_i - z_{i-1}}^2} \]
\[ L = \sum_{i=1}^{n} d_{i} \]
\[ t_i \text{ is the parameter value at point } P_i \]
After calculating the node ${t_i}$, the spline is used to fit ${t_i}$ and ${y_i}$, ${t_i}$ and ${y_i}$ respectively, and the spline curve is obtained.
\subsection{Equidistant Node Parameterization}
Equidistant node parameterization is a method used in curve fitting where the parameter values (often denoted as \( t \)) are assigned to the data points in such a way that the distance between consecutive parameter values is constant. This is in contrast to other parameterization methods, such as the cumulative chordal length parameterization, where the parameter values are determined based on the geometric distances between the data points.

\section{UniqueSpline.hpp}
UniqueSpline.hpp contains the declaration of a class SpecialBSpline. This class is designed to compute and evaluate a quadratic B-spline that fits a given set of data points with specific boundary conditions in the definition of Thm 3.58.
\subsection*{B-Spline Basis Function}
\[ B_{i,0}(x) = \begin{cases} 
1 & \text{if } t_i \leq x < t_{i+1} \\
0 & \text{otherwise}
\end{cases} \]
\[ B_{i,k}(x) = \frac{x - t_i}{t_{i+k} - t_i} B_{i,k-1}(x) + \frac{t_{i+k+1} - x}{t_{i+k+1} - t_{i+1}} B_{i+1,k-1}(x) \]

\subsection*{Linear System for Coefficients}
\subsection*{solveLinearSystem}
Solves the linear system \( M \cdot a = b \) to compute the B-spline coefficients.
\subsection*{applyBoundaryConditions}
Applies boundary conditions to compute the first and last coefficients.
\[
    a_0 = 2f(1)-a_1 , a_N = 2f(N)-a_{N-1} 
\]
\subsection*{getSplineValue}
Evaluates the B-spline at a given point \( x \).
\section{Sphere.hpp}
\subsection{Design}
The design is to utilize a spline interpolation technique to create a smooth curve that fits the given points on a spherical surface. The process involves projecting the 3D points onto a 2D plane, fitting a spline to these points, and then mapping the spline back onto the sphere.

\subsection{Mathematical Theory}
\subsubsection*{Projection}
The points are projected onto a 2D plane using a division that normalizes the points with respect to the z coordinate and the initial length of the point.\\
The projection of a 3D point \((x, y, z)\) onto a 2D plane is given by:
\[ x_{\text{projected}} = \frac{x}{(1 - \frac{z}{\text{length}})\text{length}} \]
\[ y_{\text{projected}} = \frac{y}{(1 - \frac{z}{\text{length}})\text{length}} \]
\subsubsection*{Spline Interpolation}
 A spline is used to interpolate between the projected points. The PPForm spline is a type of cubic spline that is suitable for this purpose.
\subsubsection*{Normalization}
After interpolation, the points are normalized to ensure they lie on the unit sphere. They are then re-scaled to match the original radius of the sphere.\\
Normalization of a point \((x, y)\) to lie on the unit sphere:
\[ x_{\text{sphere}} = \frac{x}{\sqrt{x^2 + y^2 + 1}} \]
\[ y_{\text{sphere}} = \frac{y}{\sqrt{x^2 + y^2 + 1}} \]
\[ z_{\text{sphere}} = \frac{1}{\sqrt{x^2 + y^2 + 1}} \]

\subsubsection*{Re-scaling}
Re-scaling to the original radius:
\[ x_{\text{rescaled}} = x_{\text{sphere}} \cdot \frac{\text{original length}}{\sqrt{x_{\text{sphere}}^2 + y_{\text{sphere}}^2 + z_{\text{sphere}}^2}} \]
\[ y_{\text{rescaled}} = y_{\text{sphere}} \cdot \frac{\text{original length}}{\sqrt{x_{\text{sphere}}^2 + y_{\text{sphere}}^2 + z_{\text{sphere}}^2}} \]
\[ z_{\text{rescaled}} = z_{\text{sphere}} \cdot \frac{\text{original length}}{\sqrt{x_{\text{sphere}}^2 + y_{\text{sphere}}^2 + z_{\text{sphere}}^2}} \]
\end{document}  